package com.yiwei.zxp.activity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.allen.library.CircleImageView;
import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.yiwei.zxp.BussinessMainActivity;
import com.yiwei.zxp.R;
import com.yiwei.zxp.adapter.CommentPhotoAdapter;
import com.yiwei.zxp.adapter.GoodsDetailAdapter;
import com.yiwei.zxp.adapter.ShopInfoImageAdapter;
import com.yiwei.zxp.api.Api;
import com.yiwei.zxp.api.bean.BuyListBean;
import com.yiwei.zxp.api.bean.FavoriteAddBean;
import com.yiwei.zxp.api.bean.FavoriteDeleteBean;
import com.yiwei.zxp.api.bean.GoodIdBean;
import com.yiwei.zxp.api.bean.GoodsCommentLabelBean;
import com.yiwei.zxp.api.bean.GoodsCommentListBean;
import com.yiwei.zxp.api.bean.ShopAddBean;
import com.yiwei.zxp.api.bean.ShopGoodsListBean;
import com.yiwei.zxp.api.model.GoodsCommentListModel;
import com.yiwei.zxp.api.model.GoodsDetailModel;
import com.yiwei.zxp.api.model.ShopMallListModel;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.constant.UserInfoGlobal;
import com.yiwei.zxp.event.HomePagerEvent;
import com.yiwei.zxp.event.ShopCartEvent;
import com.yiwei.zxp.util.DateTime;
import com.yiwei.zxp.util.Dialog;
import com.yiwei.zxp.util.GlideImageLoader;
import com.yiwei.zxp.util.Network;
import com.yiwei.zxp.util.RxLifeUtil;
import com.yiwei.zxp.util.Spans;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.util.UI;
import com.yiwei.zxp.util.Util;
import com.yiwei.zxp.view.BottomIconText;
import com.yiwei.zxp.view.FullyLinearLayoutManager;
import com.yiwei.zxp.view.StarNumberView;
import com.yiwei.zxp.view.V19FrameLayout;
import com.yiwei.zxp.view.V19RelativeLayout;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class BuyerGoodDetailsV2Activity extends BaseActivity implements NestedScrollView.OnScrollChangeListener {


    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.btn_share)
    ImageView btnShare;
    @BindView(R.id.txt_goods_info)
    TextView txtGoodsInfo;
    @BindView(R.id.txt_goods_address)
    TextView txtGoodsAddress;
    @BindView(R.id.txt_goods_type)
    TextView txtGoodsType;
    @BindView(R.id.txt_goods_param)
    TextView txtGoodsParam;
    @BindView(R.id.list_image)
    RecyclerView listImage;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    @BindView(R.id.btn_params)
    LinearLayout btnParams;

    @BindView(R.id.btn_top_cart)
    ImageView btnTopCart;
    @BindView(R.id.btn_shop)
    BottomIconText btnShop;
    @BindView(R.id.btn_collection)
    BottomIconText btnCollection;
    @BindView(R.id.btn_add_cart)
    SuperButton btnAddCart;
    @BindView(R.id.btn_buy_now)
    SuperButton btnBuyNow;
    @BindView(R.id.txt_goods_sell)
    TextView txtGoodsSell;
    @BindView(R.id.index_banner)
    Banner banner;
    @BindView(R.id.txt_goods_title)
    TextView txtGoodsTitle;
    @BindView(R.id.btn_check_all)
    TextView btnCheckAll;
    @BindView(R.id.toolbar)
    V19FrameLayout toolbar;
    @BindView(R.id.btn_back_sec)
    ImageView btnBackSec;
    @BindView(R.id.btn_top_good)
    TextView btnTopGood;
    @BindView(R.id.btn_top_comment)
    TextView btnTopComment;
    @BindView(R.id.btn_top_detail)
    TextView btnTopDetail;
    @BindView(R.id.btn_top_cart_sec)
    ImageView btnTopCartSec;
    @BindView(R.id.btn_share_sec)
    ImageView btnShareSec;
    @BindView(R.id.toolbar_sec)
    V19RelativeLayout toolbarSec;
    @BindView(R.id.txt_goods_content)
    TextView txtGoodsContent;
    @BindView(R.id.view_step_one)
    View viewStepOne;
    @BindView(R.id.layout_top_good)
    LinearLayout layoutTopGood;
    @BindView(R.id.view_step_two)
    View viewStepTwo;
    @BindView(R.id.layout_top_comment)
    LinearLayout layoutTopComment;
    @BindView(R.id.view_step_three)
    View viewStepThree;
    @BindView(R.id.layout_top_detail)
    LinearLayout layoutTopDetail;
    @BindView(R.id.layout_img_detail)
    LinearLayout layoutImgDetail;
    @BindView(R.id.txt_goods_number)
    TextView txtGoodsNumber;
    @BindView(R.id.btn_comment_all)
    TextView btnCommentAll;
    @BindView(R.id.img_icon)
    CircleImageView imgIcon;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.star_view)
    StarNumberView starView;
    @BindView(R.id.txt_time)
    TextView txtTime;
    @BindView(R.id.txt_content)
    TextView txtContent;
    @BindView(R.id.list_comment)
    RecyclerView listComment;
    @BindView(R.id.layout_comment_empty)
    LinearLayout layoutCommentEmpty;
    @BindView(R.id.img_shop_icon)
    ImageView imgShopIcon;
    @BindView(R.id.txt_shop_name)
    TextView txtShopName;
    @BindView(R.id.txt_shop_cate)
    TextView txtShopCate;
    @BindView(R.id.btn_shop_go)
    SuperButton btnShopGo;
    @BindView(R.id.list_shop)
    RecyclerView listShop;
    @BindView(R.id.layout_shop_info_top)
    LinearLayout layoutShopInfoTop;
    @BindView(R.id.btn_comment_all_sec)
    SuperButton btnCommentAllSec;
    @BindView(R.id.fl_comment)
    FrameLayout flComment;
    @BindView(R.id.btn_call)
    BottomIconText btnCall;
    @BindView(R.id.layout_bottom)
    LinearLayout layoutBottom;
    @BindView(R.id.btn_go_top)
    LinearLayout btnGoTop;
    private Unbinder unbiner;
    private GoodsDetailAdapter bottomAdapter;
    private int x24;
    private GoodsDetailModel.DatasBean totalData;
    private boolean isCollection = false;
    private int bannerBottom;
    private int secToolbarDistance;
    //    private float minHeaderHeight;
    private int alphaDistance;
    //    private int imgDetailDistance = 0;
    private ShopInfoImageAdapter shopInfoImageAdapter;
//    private int layoutCommentDistance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buyer_goods_detail_v2);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        banner.post(new Runnable() {
            @Override
            public void run() {
//                minHeaderHeight = getResources().getDimension(R.dimen.y98);
                bannerBottom = banner.getBottom();
                alphaDistance = getResources().getDimensionPixelSize(R.dimen.y100);
                secToolbarDistance = bannerBottom + alphaDistance;
//                imgDetailDistance = layoutImgDetail.getTop();
//                layoutCommentDistance = flComment.getTop();
            }
        });
        scrollView.setOnScrollChangeListener(this);
        banner.setImageLoader(new GlideImageLoader());
        banner.setIndicatorGravity(BannerConfig.CENTER);
        x24 = getResources().getDimensionPixelSize(R.dimen.x24);
        String good_id = getIntent().getStringExtra("goods_id");
        String goods_no = getIntent().getStringExtra("goods_no");
        boolean is_shixiao = getIntent().getBooleanExtra("shixiao", false);
        if (is_shixiao) {
            layoutBottom.setVisibility(View.GONE);
        } else {
            layoutBottom.setVisibility(View.VISIBLE);
        }
        bottomAdapter = new GoodsDetailAdapter(this);
        FullyLinearLayoutManager mLayoutManager = new FullyLinearLayoutManager(this);
        listImage.setLayoutManager(mLayoutManager);
        listImage.setNestedScrollingEnabled(false);
        listImage.setAdapter(bottomAdapter);
        getGoodsDetail(good_id, goods_no);


    }

    public void getGoodsDetail(String goods_id, String goods_no) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        GoodIdBean bean = new GoodIdBean();
        bean.goods_id = goods_id;
        bean.goods_no = goods_no;
        Api.api_service.getGoodsDetail(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    totalData = result.datas;
                    setGoodsData(result.datas);

                    getShopGoodsList(result.datas.shop_id);
                    getGoodsCommentLabel(result.datas.goods_id);
                });
    }


    //    获取店铺商品
    public void getShopGoodsList(String shop_id) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        ShopGoodsListBean bean = new ShopGoodsListBean();
        bean.shop_id = shop_id;

        Api.api_service.getShopGoodsList(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.datas != null && result.datas.size() != 0) {
                        shopInfoImageAdapter = new ShopInfoImageAdapter(this);
                        listShop.setLayoutManager(new GridLayoutManager(this, 3));
                        listShop.setAdapter(shopInfoImageAdapter);
                        if (result.datas.size() <= 3) {
                            shopInfoImageAdapter.update(result.datas);
                        } else {
                            List<ShopMallListModel.DatasBean> data = new ArrayList<ShopMallListModel.DatasBean>();
                            for (int i = 0; i < 3; i++) {
                                data.add(result.datas.get(i));
                            }
                            shopInfoImageAdapter.update(data);
                        }
                    }
                });
    }


    private void setGoodsData(GoodsDetailModel.DatasBean item) {

        banner.setImages(item.photos).start();

        Spanned txt_money = Spans.with(this).
                font("￥", x24, 0xffFF0030).style(Typeface.BOLD).
                font(item.price, getResources().getDimensionPixelSize(R.dimen.x48), 0xffFF0030).style(Typeface.BOLD).
                build();
        txtGoodsTitle.setText(txt_money);

        txtGoodsContent.setText(item.title);

        String fee = "";
        if (Float.valueOf(item.deliver_fee) == 0) {
            fee = "免运费";
            txtGoodsInfo.setTextColor(0xff999999);
        } else {
            fee = "￥" + item.deliver_fee;
            txtGoodsInfo.setTextColor(0xffFF0030);
        }
        txtGoodsSell.setText("月销：" + item.sell + "笔");
        txtGoodsInfo.setText(fee);
        txtGoodsNumber.setText("库存：" + item.inventory + "件");
        txtGoodsAddress.setText(item.province + item.city);

        txtGoodsType.setText(item.cate_name);
        if (item.params != null && item.params.size() >= 0) {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < item.params.size(); i++) {
                builder.append(item.params.get(i).name);
                builder.append("、");
            }
            txtGoodsParam.setText(builder.substring(0, builder.length() - 1));
        }

        bottomAdapter.update(item.details);

//        是否收藏
        if (item.is_favorites.equals("1")) {
            isCollection = true;
            btnCollection.setTextColor(0xffFF0030);
            btnCollection.setDrawable(R.mipmap.img_detail_collcetion);
        } else {
            isCollection = false;
            btnCollection.setTextColor(0xff5D5F6A);
            btnCollection.setDrawable(R.mipmap.img_detail_uncollection);
        }


//        设置店铺信息
        txtShopName.setText(item.shop_name);
        Glide.with(this).load(item.shop_img).placeholder(R.mipmap.img_default_shop_icon).into(imgShopIcon);
        if (item.cate_lists != null && item.cate_lists.size() != 0) {
            StringBuilder builder = new StringBuilder();
            builder.append("经营分类：");
            for (int i = 0; i < item.cate_lists.size(); i++) {
                builder.append(item.cate_lists.get(i).catname);
                builder.append("、");
            }
            txtShopCate.setText(builder.substring(0, builder.length() - 1));
        }

    }


    public void scrollToPosition(int x, int y) {

        ObjectAnimator xTranslate = ObjectAnimator.ofInt(scrollView, "scrollX", x);
        ObjectAnimator yTranslate = ObjectAnimator.ofInt(scrollView, "scrollY", y);

        AnimatorSet animators = new AnimatorSet();
        animators.setDuration(1000L);
        animators.playTogether(xTranslate, yTranslate);
        animators.start();
    }

    //   获取宝贝评价标签，顺便获取总数
    public void getGoodsCommentLabel(String goods_id) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        GoodsCommentLabelBean bean = new GoodsCommentLabelBean();
        bean.goods_id = goods_id;

        Api.api_service.getGoodsCommentLabel(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {

                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.datas != null && result.datas.size() != 0) {
                        boolean isEmpty = true;
                        for (int i = 0; i < result.datas.size(); i++) {
                            if (result.datas.get(i).keyword.equals("0") && !result.datas.get(i).num.equals("0")) {
                                isEmpty = false;
                                getSellCommentLists(goods_id);
                            }
                        }
                        if (isEmpty) {
                            layoutCommentEmpty.setVisibility(View.VISIBLE);
                        }
                    } else {
                        layoutCommentEmpty.setVisibility(View.VISIBLE);
                    }
                });
    }

    public void getSellCommentLists(String goods_id) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        GoodsCommentListBean bean = new GoodsCommentListBean();
        bean.goods_id = goods_id;

        Api.api_service.getGoodsCommentList(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {

                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.datas != null && result.datas.size() != 0) {
                        listComment.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
                        CommentPhotoAdapter adapter = new CommentPhotoAdapter(this);
                        listComment.setAdapter(adapter);
                        GoodsCommentListModel.DatasBean itembean = result.datas.get(0);
                        adapter.update(itembean.photos);
                        txtName.setText(itembean.username);
                        Glide.with(this).load(itembean.icon).asBitmap().error(R.mipmap.img_my_default).into(imgIcon);
                        txtContent.setText(itembean.content);
                        txtTime.setText(DateTime.toDate(Long.valueOf(itembean.time) * 1000));
                        starView.setStar(Integer.valueOf(itembean.score));
                        layoutCommentEmpty.setVisibility(View.GONE);
                    } else {
                        layoutCommentEmpty.setVisibility(View.VISIBLE);
                    }
                });
    }

    //    添加购物车
    public void getCartAdd() {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        ShopAddBean bean = new ShopAddBean();
        bean.shop_id = totalData.shop_id;
        bean.goods_id = totalData.goods_id;
        bean.goods_no = totalData.goods_no;
        Api.api_service.getShopAdd(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    EventBus.getDefault().post(new ShopCartEvent());
                    ToastUtil.makeCartTips("加入购物车成功");
                });
    }

    public void getFavoriteAdd(List<FavoriteAddBean> item) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();

        Api.api_service.getFavoriteAdd(item).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    isCollection = true;
                    ToastUtil.makeText(this, "收藏成功");
                    btnCollection.setTextColor(0xffFF0030);
                    btnCollection.setDrawable(R.mipmap.img_detail_collcetion);
                });
    }

    public void getFavoriteDelete(String goods_id) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        FavoriteDeleteBean bean = new FavoriteDeleteBean();
        bean.goods_id = goods_id;
        Api.api_service.getFavoriteDelete(bean).compose(RxLifeUtil.loginCheckOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    isCollection = false;
                    ToastUtil.makeText(this, "取消收藏");
                    btnCollection.setTextColor(0xff5D5F6A);
                    btnCollection.setDrawable(R.mipmap.img_detail_uncollection);
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }

    @Override
    public void onStart() {
        super.onStart();
        banner.startAutoPlay();
    }

    @Override
    public void onStop() {
        super.onStop();
        banner.stopAutoPlay();
    }

    @OnClick({R.id.btn_check_all, R.id.btn_back, R.id.btn_share})
    public void onViewClicked(View view) {
        if (UI.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.btn_check_all:
                Dialog.showGoodsParams(this, totalData.params);
                break;
            case R.id.btn_back:
                finish();
                break;

            case R.id.btn_share:
                break;
        }
    }

    @OnClick({R.id.btn_call, R.id.btn_top_cart, R.id.btn_shop, R.id.btn_collection, R.id.btn_add_cart, R.id.btn_buy_now})
    public void onViewClicked1(View view) {
        if (UI.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.btn_top_cart:
                EventBus.getDefault().post(new HomePagerEvent(2));
                Util.startActivity(this, BussinessMainActivity.class);
                finish();
                break;
            case R.id.btn_call:
                Dialog.showDefaultDialog(this, "", "联系客服\n" + totalData.shop_phone, "取消", "呼叫", false, new Dialog.DialogDefaultClickListener() {
                    @Override
                    public void confirm() {
                        Intent intentCall = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + totalData.shop_phone));
                        intentCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intentCall);
                    }

                    @Override
                    public void cancel() {

                    }
                });


                break;
            case R.id.btn_shop:
                if (totalData != null) {
                    Intent intent = new Intent(this, BussinessShopDetailActivity.class);
                    intent.putExtra("shop_id", totalData.shop_id);
                    intent.putExtra("title", totalData.shop_name);
                    startActivity(intent);
                    overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                }
                break;
            case R.id.btn_collection:
                if (!UserInfoGlobal.isLogin()) {
                    Util.startActivity(this, LoginNewActivity.class);
                    return;
                }
                if (totalData == null) return;
                if (isCollection) {
                    getFavoriteDelete(totalData.goods_id);
                } else {
                    List<FavoriteAddBean> data = new ArrayList<>();
                    data.add(new FavoriteAddBean(totalData.shop_id, totalData.goods_no, totalData.goods_id));
                    getFavoriteAdd(data);
                }
                break;
            case R.id.btn_add_cart:
                if (!UserInfoGlobal.isLogin()) {
                    Util.startActivity(this, LoginNewActivity.class);
                    return;
                }
                if (totalData != null)
                    getCartAdd();
                break;
            case R.id.btn_buy_now:
                if (!UserInfoGlobal.isLogin()) {
                    Util.startActivity(this, LoginNewActivity.class);
                    return;
                }
                if (totalData != null) {
                    Intent intent = new Intent(this, SureOrderActivity.class);
                    intent.putExtra("data", getBuyList());
                    startActivity(intent);
                    finish();
                }
                break;
        }
    }

    public BuyListBean getBuyList() {
        BuyListBean data = new BuyListBean();
        data.items = new ArrayList<>();

        BuyListBean.ItemsBean bean = new BuyListBean.ItemsBean();
        bean.shop_id = totalData.shop_id;
        bean.goods = new ArrayList<>();
        bean.goods.add(new BuyListBean.ItemsBean.GoodsBean(totalData.goods_no, "1"));
        data.items.add(bean);
        return data;
    }

    @Override
    public void onScrollChange(NestedScrollView v, int x, int y, int oldScrollX, int oldScrollY) {
        //Y轴偏移量
        float scrollY = scrollView.getScrollY();

        if (scrollY < bannerBottom) {
            toolbar.setVisibility(View.VISIBLE);
            toolbar.setAlpha(1);
            toolbarSec.setVisibility(View.GONE);
        } else if (scrollY >= bannerBottom && scrollY <= secToolbarDistance) {
            float one_offset = (scrollY - bannerBottom) / alphaDistance;
            float offset = 1 - (scrollY - bannerBottom) / alphaDistance;
            toolbar.setVisibility(View.VISIBLE);
            toolbarSec.setVisibility(View.VISIBLE);
            toolbar.setAlpha(offset);
            toolbarSec.setAlpha(one_offset);
//            toolbar.setBackgroundColor(Color.argb((int) (one_offset * 255), 56, 169, 253));
//            toolbarSec.setBackgroundColor(Color.argb((int) (offset * 255), 255, 255, 255));
        } else {
            toolbar.setVisibility(View.GONE);
            toolbarSec.setVisibility(View.VISIBLE);
        }

        if (scrollY > layoutImgDetail.getTop()) {
            btnGoTop.setVisibility(View.VISIBLE);
            setStep(2);
        } else if (scrollY > flComment.getTop()) {
            setStep(1);
            btnGoTop.setVisibility(View.GONE);
        } else {
            setStep(0);
            btnGoTop.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.btn_go_top, R.id.btn_back_sec, R.id.layout_top_good, R.id.layout_top_comment, R.id.layout_top_detail, R.id.btn_top_cart_sec})
    public void onViewClicked2(View view) {
        switch (view.getId()) {
            case R.id.btn_back_sec:
                finish();
                break;
            case R.id.btn_go_top:
                scrollView.post(new Runnable() {
                    @Override
                    public void run() {
                        scrollToPosition(0, 0);
                        setStep(0);
                    }
                });
                break;
            case R.id.layout_top_good:
                scrollView.post(new Runnable() {
                    @Override
                    public void run() {
                        scrollToPosition(0, 0);
                        setStep(0);
                    }
                });
                break;
            case R.id.layout_top_comment:
                scrollView.post(new Runnable() {
                    @Override
                    public void run() {
                        scrollToPosition(0, flComment.getTop());
                        setStep(1);
                    }
                });
                break;
            case R.id.layout_top_detail:
                scrollView.post(new Runnable() {
                    @Override
                    public void run() {
                        scrollToPosition(0, layoutImgDetail.getTop());
                        setStep(2);
                    }
                });
                break;
            case R.id.btn_top_cart_sec:
                EventBus.getDefault().post(new HomePagerEvent(2));
                Util.startActivity(this, BussinessMainActivity.class);
                finish();
                break;
        }
    }

    private void setStep(int step) {
        btnTopGood.setTextColor(0xff000000);
        btnTopComment.setTextColor(0xff000000);
        btnTopDetail.setTextColor(0xff000000);
        viewStepOne.setVisibility(View.GONE);
        viewStepTwo.setVisibility(View.GONE);
        viewStepThree.setVisibility(View.GONE);
        switch (step) {
            case 0:
                btnTopGood.setTextColor(0xffFF0030);
                viewStepOne.setVisibility(View.VISIBLE);
                break;
            case 1:
                btnTopComment.setTextColor(0xffFF0030);
                viewStepTwo.setVisibility(View.VISIBLE);
                break;
            case 2:
                btnTopDetail.setTextColor(0xffFF0030);
                viewStepThree.setVisibility(View.VISIBLE);
                break;
        }
    }

    @OnClick({R.id.btn_shop_go, R.id.btn_comment_all, R.id.btn_comment_all_sec})
    public void onViewClicked3(View view) {
        switch (view.getId()) {
            case R.id.btn_shop_go:
                if (totalData != null) {
                    Intent intent = new Intent(this, BussinessShopDetailActivity.class);
                    intent.putExtra("shop_id", totalData.shop_id);
                    intent.putExtra("title", totalData.shop_name);
                    startActivity(intent);
                    overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                }
                break;
            case R.id.btn_comment_all:
            case R.id.btn_comment_all_sec:
                if (totalData != null) {
                    Intent intent = new Intent(this, GoodsCommentActivity.class);
                    intent.putExtra("goods_id", totalData.goods_id);
                    startActivity(intent);
                    overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                }
                break;
        }
    }
}
